import React, { useState, useEffect } from 'react'

function useLoginState () {
  const [loginState, setLoginState] = useState(localStorage.getItem('loginState') === 'true' || false)
  useEffect(() => {
    // 通过接口获取到用户的登录状态
    const res = { data: { loginState: false}}
    setLoginState(res.data.loginState)
  }, [])
  return loginState
}

function App() {
  // const loginState = useLoginState()
  const [loginState, setLoginState] = useState(localStorage.getItem('loginState') === 'true' || false)
  useEffect(() => {
    // 通过接口获取到用户的登录状态
    const res = { data: { loginState: false}}
    setLoginState(res.data.loginState)
  }, [])
  return (
    <div>
      {
        loginState ? '已登录' : '未登录'
      }
    </div>
  )
}

export default App
